# -*- coding: utf-8 -*- 
from django.db import models
from website.constant import SYSUSER_STATE_CHOICES
from website.employecontrol.models import Employe
from website.models import Menu
from website.resourcecontrol.models import Company
import datetime
# Create your models here.

# 系统用户
class SysUser(models.Model):
    login_name=models.CharField(max_length=30)# 工号
    login_pwd=models.CharField(max_length=30)# 密码
    login_state=models.IntegerField(max_length=1,default=0,choices=SYSUSER_STATE_CHOICES)#状态
    login_last=models.DateTimeField(blank=True, null=True)#最后一次登录时间 
    create_time=models.DateTimeField(default=datetime.datetime.now()) #创建时间
    is_superuser=models.IntegerField(max_length=1,default=0)
    mac=models.CharField(max_length=50,blank=True, null=True)
    ip=models.IPAddressField(blank=True, null=True)
    employe=models.ForeignKey(Employe,blank=True, null=True,related_name='sysuser_employe')
    role=models.ForeignKey('SysRole',blank=True, null=True,related_name='sysuser_role')
    index_record=models.ManyToManyField('IndexRecord',blank=True, null=True)
    
# 系统用户角色
class SysRole(models.Model):
    role_name=models.CharField(max_length=30)
    role_menu=models.ManyToManyField(Menu,blank=True, null=True)
    
#系统登录日志
class SysLoginLog(models.Model):
    login_time=models.DateTimeField(default=datetime.datetime.now())
    login_ip=models.IPAddressField(blank=True, null=True)
    login_name=models.CharField(max_length=30)
    company=models.ForeignKey(Company,blank=True, null=True,related_name='sysloginlog_company')
    employe=models.ForeignKey(Employe,blank=True, null=True,related_name='sysloginlog_employe')

#首页资源
class IndexRecord(models.Model):
    text=models.CharField(max_length=50)
    portlet=models.CharField(max_length=100)
    target=models.CharField(max_length=100,blank=True, null=True)
   

    
    